local skel = fk.CreateSkill {
  name = "rmt__zhijing",
  tags = {Skill.Compulsory},
  dynamic_desc = function (self, player, lang) -- 宝宝标记这一块
    local max = 0
    for _, p in pairs(Fk:currentRoom().alive_players) do
      max = math.max(max, p:getMark("rmt__zhijing-round"))
    end
    return "rmt__zhijing_dyn:" .. player:getMark("rmt__zhijing-round") .. ":" .. max
  end,
}

Fk:loadTranslationTable{
  ["rmt__zhijing"] = "职竞",
  [":rmt__zhijing"] = "锁定技，当你使用牌时，若本轮获得牌数最多的角色为你，此牌伤害基数+1，否则你摸一张牌。",

  [":rmt__zhijing_dyn"] = "锁定技，当你使用牌时，若本轮获得牌数最多的角色为你，此牌伤害基数+1，否则你摸一张牌。"..
  "（我本轮获得牌数/最大={1}/{2}）",

  ["$rmt__zhijing1"] = "众生皆苦，生者当獊囊登阶；遍野横骨，死者为乱世更迭。",
  ["$rmt__zhijing2"] = "汝等所为，吾之乘石；吾等所谋，汝之讣告。",
}

skel:addEffect(fk.CardUsing, {
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local maxNum = 0
    for _, p in pairs(room.alive_players) do
      maxNum = math.max(maxNum, p:getMark("rmt__zhijing-round"))
    end
    if player:getMark("rmt__zhijing-round") >= maxNum then
      if data.card.is_damage_card then
        player:broadcastSkillInvoke(self.name, 1)
        room:notifySkillInvoked(player, self.name, "offensive")
        data.additionalDamage = (data.additionalDamage or 0) + 1
      end
    else
      player:broadcastSkillInvoke(self.name, 2)
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:drawCards(1, self.name)
    end
  end,
})

--- 记录每个人本轮获得牌数
skel:addEffect(fk.AfterCardsMove, {
  can_refresh = function (self, event, target, player, data)
    return not player.dead
  end,
  on_refresh = function (self, event, target, player, data)
    local num = 0
    for _, move in ipairs(data) do
      if move.to == player and move.toArea == Card.PlayerHand then
        num = num + #move.moveInfo
      end
    end
    if num > 0 then
      player.room:addPlayerMark(player, "rmt__zhijing-round")
    end
  end,
})

--- 记录大查特查
skel:addAcquireEffect(function (self, player, is_start)
  local room = player.room
  local numMap = {}
  room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
    for _, move in ipairs(e.data) do
      if move.to and move.toArea == Card.PlayerHand then
        numMap[move.to] = (numMap[move.to] or 0) + #move.moveInfo
      end
    end
    return false
  end, Player.HistoryRound)
  for to, num in pairs(numMap) do
    room:setPlayerMark(to, "rmt__zhijing-round", num)
  end
end)


return skel
